package com.yozinga.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.yozinga.R;
import com.yozinga.fragment.YozingaDialogFragment.ButtonListener;
import com.yozinga.twitter.TwitterHomeActivity;
import com.yozinga.util.NativeAppInvoker;
import com.yozinga.util.SharedData;

public class ShareDialogFragment extends DialogFragment implements OnItemClickListener,ButtonListener {

	String[] items = { "FaceBook", "Twitter", "Email"};
	ListView listView;
	Context mContext;
	String mdealName,mdealTagLine;
	ShareListener mShareListener;
	SharedData sharedData; 
	public ShareDialogFragment(Context context,String dealname,String dealTagLine,ShareListener shareListener) {
		mContext = context;
		mdealName = dealname;
		mdealTagLine = dealTagLine;
		mShareListener = shareListener;
		sharedData = new SharedData(mContext);
		
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		getDialog().setTitle("Share Deal");
		View v = inflater.inflate(R.layout.fragment_sharedialog, container, false);
		listView = (ListView) v.findViewById(android.R.id.list);
		listView.setOnItemClickListener(this);
		return v;
	}
	public interface ShareListener{
		public void faceBookShare();
		public void twitterShare();
	}
	
	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		listView.setAdapter(new ArrayAdapter<String>(getActivity(),
				R.layout.adapter_sharedeal,
				items));
	}
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
		switch (position) {
		case 0:
			mShareListener.faceBookShare();
			//postMessage();
			//startActivity(new Intent(getActivity(),com.yozinga.facebook.AndroidFacebookSample.class));
			break;
		case 1:
			new SharedData(getActivity()).setTwitter(true);
			///YozingaDialogFragment dialogFragment = new YozingaDialogFragment(this,"twett Deal","Post",mContext);
			//dialogFragment.show(getFragmentManager(), "fragment_share_twitter");
			//mShareListener.twitterShare();
			startActivity(new Intent(getActivity(),TwitterHomeActivity.class));
			sharedData.setTwitterStatus(mdealName+" ,"+mdealTagLine);
			break;
		default:
			NativeAppInvoker nativeAppInvoker = new NativeAppInvoker(getActivity());
			nativeAppInvoker.emailInvoker("", "",mdealName+" ,"+mdealTagLine);
			break;
		}
		dismiss();

	}

	@Override
	public void locationValue(String locationValue) {

	}
}